//冒泡排序
/* let arr = [1, 2, 3, 4, 1, 5, 6, 7]
function buller(arr){
    for(let i=0;i<arr.length-1;i++){
        for(let j=i+1;j<arr.length;j++){
            if(arr[j]<arr[i]){
                [arr[j],arr[i]] = [arr[i],arr[j]]
            }
        }
    }
    return arr
}
console.log(buller(arr)); */

//选择排序
/*  let arr = [ 2, 3, 4, 1, 5, 6, 7,1,2,32,432,4,543,5]

function buller(arr){
    for(let i=0;i<arr.length;i++){
        for(let j=i;j<arr.length;j++){
            if(arr[j]<=arr[i]){
            [arr[i],arr[j]] = [arr[j],arr[i]]
            }  
        }
        
    }
    return arr
}
console.log(buller(arr)); */


//插入排序
/* 
let arr = [ 2, 3, 4, 1, 5, 6, 7,1,2,32,432,4,543,5]
function buller(arr){
    for(let i=0;i<arr.length;i++){
        let j=i
        let ans = arr[j]
        while(ans<arr[j-1]){         //关键
                arr[j] = arr[j-1]
                j--
        }
         arr[j] = ans
    }
    return arr
}
console.log(buller(arr)); */


//快速排序
/* 
let arr = [ 2, 3, 4, 1, 5, 6, 7,1,2,32,432,4,543,5]
function buller(arr){
    let mid = arr[0]
    
    for(let i=0;i<arr.length;i++){
        if(arr[i]>=arr[0]){

        }
    }
} */


//归并排序
//合并数组
/* let arr = [ 2, 3, 4, 1, 5, 6, 7,1,2,32,432,4,543,5]
function guibingsort(arr){
    if(arr.length<=1)return arr
    let left = []
    let right = []
    let midIndex = Math.floor(arr.length/2)
    let mid = arr.splice(midIndex,1)[0]
    for(let i=0;i<arr.length;i++){
        if(arr[i]>mid){
            right.push(arr[i])
        }else{
            left.push(arr[i])
        }
    }
    return [...guibingsort(left),mid,...guibingsort(right)]
}
console.log(guibingsort(arr)); */

// 快排

//比归并少占一些空间
let arr = [ 2, 3, 4, 1, 5, 6, 7,1,2,32,432,4,543,5]
function quicksort(arr){
    let left = arr.length-1
    let right = 0
    let mid = arr[Math.floor(arr.length/2)]

}
function pX(left,right,arr){
    let mid = arr[0]
    while(left<right){
        if(arr)
    }
}
